Loading, please wait...

A to Z Full Forms and Acronyms

AzureDevOps- Automated Testing using Azure Storage with Azurite

Jun 24, 2021 Azure table storage, 2689 Views
AzureDevOps- Automated Testing using Azure Storage with Azurite

AzureDevOps- Automated Testing using Azure Storage with Azurite

Recently there was a new requirement from our QA/testing team to do end-to-end Integration testing for our Microsoft .net core code which relies on Azure table storage.

In order to achieve one of the approach to create a separate Azure Storage account exclusively for tests. This means we have to manage storage state yourself. Each time you run tests, you have to be sure that your resource exists, you have to manage connections strings and current state of the data in storage.

Currently to deal with this situation best option is to go with Azure Storage Emulator and Azurite Emulator.

Azurite and Azure Storage Emulator

There are two storage emulators available as of today, Azure Storage Emulator and the Azurite. While the latter is an open-source multi-platform successor of the first. 

Set up

As a part of the demo lets focus using Azurite.

Lets start Installing Azurite using AzureDevOps pipeline with Microsoft hosted agent and then integrate our test cases. Lets go through all the tasks which needs to be a part of AzureDevOps pipeline.

  1. First as a part of our pipeline we need Install python library → Make sure to go with latest version of Python. 

steps: →task: UsePythonVersion@0 displayName: ‘Use Python 3.9.9’ inputs: versionSpec: 3.9.9

2. Next we have to Install and Run Azurite using Bash on Microsoft hosted agent. Once you run the step you can see it shows the message as 
“Azurite Blob service is starting with https://127.0.0.1:10000

using below command to install → Used Bash script task.

npm install -g azurite
mkdir azurite
azurite — silent — location azurite — debug azurite\debug.log &

3. Now lets start Azurite Emulator specifically for Azure Table storage, So passing Command line parameter you can start Azure table storage service.

start /B azurite-table

Make sure you configure connection string your .net code. Now you probably want to connect your application to the emulated storage. The easiest way of achieving that is to configure a connection string in your application. 
“ConnectionString”: “UseDevelopmentStorage=true”. 

Also Azurite provide default userid & password. Please check article for reference.

4. Next step is to configure Microsoft .Net restore and .Net Build step.

As a part of testing I specifically wants to do “Integration Testing” so added the same under arguments.

5. Now in order to get code coverage using XUnit and setting some output format such as Cobertura, I am using below argument.

/p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:Threshold=90 /p:ThresholdStat=total /p:Exclude=”[*xunit.*]”

6. Next step is to add VsTest Installer and Latter to check assemblies i have added VsTest task.

So finally this is how my build pipeline looks and sample output under Testruns in AzureDevOps Runs.

A to Z Full Forms and Acronyms

Related Article